<template>
  <div class="monitor-detail-automan">


  	<div class="monitor-automan-title detail-title">
		环保
	</div>
	<div class="monitor-automan-content detail-content">
		<div vi-if="!envInit">
			<div class="content-title detail-content-title">
				{{ envInit.title }}
			</div>
			<div class="content-lab detail-content-lab">
				<div  v-for="(items, index) in envInit.content" 
				:title="items.name"
				@click="activeDetail(items,index)" 
				:class="{active: items.active}">
					{{ items.name }}
				</div>
			</div>
		</div>
	</div>
	<div class="monitor-automan-close detail-close" @click="closeEnv">
		×
	</div>
	<common ref="common"></common>

  </div>
</template>

<script>

  import common from '../common'
  import Vue from 'vue'
  import {getEnv, ENVHTTPY, HTTPY} from '../../mock/mockdata.js'


  export default {
    props: {
      initTime: {
        type: String,
      }
    },
    data() {
      return {
        envInit: null,
        current:getEnv.content[0],
        // current: {}
        // index:0
      }
    },
    components: {
      common
    },
    watch: {
      // initTime: {
      // 	handler: function(val, oldval) {
      // 		this.getLastTime()
      // 	}
      // }
    },
    created() {
      this.envInit = getEnv
      // console.log(this.initTime)
      // this.automan.forEach((obj) => {
      // 	obj.content.forEach((res) => {
      // 		if(res.active){
      // 			this.initialAuto.push(res)
      // 			this.storeAuto.push(res)
      // 			this.lastType = res.titleOf
      // 			this.lastTypeTitle = res.titleOf
      // 		}
      // 	})
      // })
    },
    methods: {
      activeDetail(item,index){
        this.envInit.content.forEach((it)=>{
          it.active = false
        })
        item.active = true
        this.current =  item
        this.getListTime()
      },
      closeEnv(){
        // console.log(34)
        this.$emit('close-env')
      },

      getListTime(item){
        let endTime = this.initTime.replace(/\-/g,'').replace(/\:/g,'').replace(' ','')
        let startTime = this.$refs.common.getTimeCShow(endTime, -12*60)
        let url = ENVHTTPY.url+'/ZJDataCenter/api/SURF_Wea_Cbf_MUL_HOR/getSurfTimeListByTimeRange?userid=wlzx&pwd=123&dataformat=json&elements=observtimes&timeRange=['+startTime+','+endTime+']&limitCnt=10000'
        this.$http.get(url).then(data=>{
          let json = data.data
          if(json.returnCode == '0'){
            this.$emit('env-change',json.DS,this.current)
          }
        })

      }


    }
  }
</script>

<style>
</style>
